package com.qiang;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Test14 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<String>();
        list.add("林青霞");
        list.add("张曼玉");
        list.add("王祖贤");
        list.add("柳岩");

        Stream<String> listStream =
                list.stream()
                        .filter(s -> s.length() == 3);//名字长度等于3

        List<String> names =
                listStream.collect(Collectors.toList());//存到list中
        /*for (String name : names) {
            System.out.println(name);
        }//遍历*/

        Set<Integer> set = new HashSet<Integer>();
        set.add(10);
        set.add(20);
        set.add(30);
        set.add(33);
        set.add(35);

        Stream<Integer> setStream =
                set.stream().filter(age -> age > 25);//取出大于25岁的

        Set<Integer> ages = setStream.collect(Collectors.toSet());//存到set集合中
        /*for (Integer age : ages) {
            System.out.println(age);
        }//遍历*/

        String[] str = {"林青霞,30", "张曼玉,35", "王祖贤,33", "柳岩,25"};
        //String[] str = {"林青霞", "30", "张曼玉", "35", "王祖贤", "33", "柳岩", "25"};

        //筛选出大于三十岁的
        Map<String, Integer> collect = Stream.of(str).filter(s -> Integer.parseInt(s.split(",")[1]) > 30).collect(Collectors.toMap(s -> s.split(",")[0], s -> Integer.parseInt(s.split(",")[1])));
        //s.split(",")[0],s.split(",")[1])
        Set<String> keyset = collect.keySet();
        for (String key : keyset) {
            Integer value = collect.get(key);
            System.out.println(key+"=="+value);
            //System.out.println(value);
        }
    }
}
